package com.aoyy.dao;

import java.util.List;
import org.springframework.stereotype.Repository;
import com.aoyy.model.BoardManager;
/**======================================================================================
 * Board manager DAO <code>BoardManager</code> is to appoint manager for board.
 * @author this author
 * @date 2017-08-12
 * ======================================================================================= */
@Repository
public class BoardManagerDao extends BaseDao<BoardManager> {
	// Delete board manager by boardId & userId
	public void delete(Integer boardId, Integer userId) {
	    String hql = "delete from BoardManager where board.boardId = " + boardId + " and user.userId = " + userId; 
	   	this.executeUpdate(hql);
	}
	
	// Query board managers by userId 
	public List<BoardManager> queryBoardManagersByUserId(Integer userId) {
		String hql = "from BoardManager where user.userId = " + userId;
		@SuppressWarnings("unchecked")
		List<BoardManager> list = this.find(hql);
		return list;
	}
	
	// Query board manager by boardId & userId
	public BoardManager queryBoardManagerByBoardIdAndUserId(Integer boardId, Integer userId) {
		String hql = "from BoardManager where board.boardId = " + boardId + " and user.userId = " + userId;
		@SuppressWarnings("rawtypes")
		List list = this.find(hql);
		if (list != null && !list.isEmpty()) {
			return (BoardManager) list.get(0);
		}
		return null;
	}
	
}
